package com.account.basedao;

import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;

public class BaseDAO {
	AnnotationConfiguration annotationConfiguration=null;
	SessionFactory sessionFactory = null;
	Session session=null;
	Transaction  transaction=null;

	public AnnotationConfiguration getConfiguration(){
     annotationConfiguration =new AnnotationConfiguration().configure("hibernate.cfg.xml");
     return annotationConfiguration;
	}
	public SessionFactory getSessionFactory(AnnotationConfiguration annotationConfiguration){
		sessionFactory = annotationConfiguration.buildSessionFactory();
		return sessionFactory;
	}
	
	public Session getSession(SessionFactory sessionFactory){
		 return session= sessionFactory.openSession();
	}
	public Transaction getTransaction(Session session){
   transaction = session.beginTransaction();
   transaction.begin();
   return transaction;
	}
	public void save(Session session , Object object ){
		session.save(object);
	}
	public void update(){}
	public void close(SessionFactory sessionFactory , Session session , Transaction transaction){
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
	
	
}
